package com.by.controller.tower;

import com.by.bean.params.TowerQuery;
import com.by.bean.tower.Tower;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.service.tower.TowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "楼座管理")
@RequestMapping("/api")
public class TowerController extends BaseController {

    @Autowired
    TowerService towerService;

    @ApiOperation("新增楼座")
    @PostMapping("/tower")
    public ResultBean save(@RequestBody Tower tower){
        int rs = towerService.save(tower);
        return saveResult(rs);
    }

    @ApiOperation("楼座列表")
    @PostMapping("/tower/query")
    public ResultBean query(@RequestBody TowerQuery query){
        PageBean bean = towerService.query(query.toMap());
        return success("楼座列表", bean);
    }

    @ApiOperation("删除楼座")
    @DeleteMapping("/tower")
    public ResultBean delete(int id){
        int rs = towerService.delete(id);
        return deleteResult(rs);
    }

    @ApiOperation("修改楼座")
    @PutMapping("/tower")
    public ResultBean update(@RequestBody Tower tower){
        int rs = towerService.update(tower);
        return updateResult(rs);
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/tower/deleteAll")
    public ResultBean deleteAll(@RequestParam List<Integer> list){
        int rs = towerService.deleteAll(list);
        return deleteResult(rs);
    }
}
